package com.advertising.biz;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import com.advertising.dao.ApproveDAO;
import com.advertising.model.Approve;
import com.advertising.model.CloneRelease;
import com.advertising.model.Release;
import com.advertising.permissions.model.Users;
import com.tgyt.framework.dao.hspring.DAOInterface;
import com.tgyt.framework.service.BaseService;

@Service
public class ApproveService extends BaseService<Approve> implements
		IApproveService {
	@Resource(name = "approveDAO")
	private ApproveDAO approveDAO;

	@Override
	protected DAOInterface<Approve> getDAO() {

		return approveDAO;
	}

	@Override
	public List<CloneRelease> convert(List<Release> release) throws Exception {
		List<CloneRelease> clones = new ArrayList<CloneRelease>();
		/* DictionaryMemoryUtils dictionaryUtils = DictionaryMemoryUtils.getInstance();
		    Map maps = (Map)dictionaryUtils.getDictionarysMap().get("advertype");*/
		    
		if(release!=null && release.size()!=0){
			for(Iterator<Release> iter=release.iterator();iter.hasNext();){
				Release res = iter.next();
				CloneRelease c = new CloneRelease();
				BeanUtils.copyProperties(c, res);
				if(res.getUser()!=null){
					c.setUserid(res.getUser().getId()+"");
					c.setAdvername(res.getUser().getAdvername());
					c.setInternaluri(res.getUser().getInternaluri());
					c.setExternaluri(res.getUser().getExternaluri());
					c.setAddress(res.getUser().getAddress());
					c.setPidouid(res.getUser().getPidouid());
					c.setPhone(res.getUser().getPhone());
					c.setAdvertype(c.getAdvertype());
					c.setCoordinate(res.getLongitude()+" , "+res.getLatitude());
				}
				 
				clones.add(c);
			}
		}
		return clones;
		
	}
	@Override
	public Release convert(CloneRelease cloneRelease) throws Exception {
		 if(cloneRelease==null){
			 return null;
		 }
		    Release  release = new Release();
		    BeanUtils.copyProperties(release,cloneRelease);
			Users user=(Users)SecurityUtils.getSubject().getSession().getAttribute("loginuser");
			release.setUser(user);
		  
		    
		return release;
	}

}